<?php 
Load::models('envase');
class EnvaseController extends AppController 
{
    public function before_filter() {
        if ( !Auth::is_valid()){
            Router::redirect('usuario/login/');
        }else{
            $this->tipoMenu="envase";
        }
    }
    
    public function index()
    {
        
    }
     public function agregar()
    {
        if(Input::hasPost('envase')){
           
            $envase = new Envase(Input::post('envase'));
            
             if(!$envase->save()){
                Flash::error('Falló Operación');
                
                $this->envase = $this->post('envase');
              
            }else{
                Flash::success('Operación exitosa');
            }
        }
    }
    public function eliminar($id){
       $envase = new Envase();
       $envase = $envase->find($id);
       $envase->estado = "0";
            
       if ($envase->update()) {
            Flash::valid('Operación exitosa');
       }else{
           Flash::error('Falló Operación'); 
       }
        return Router::redirect('envase/listar');
    }
    
    public function listar(){
         $envase = new Envase();
         $this->envase =   $envase->find("order: tipo","conditions: estado=1");
    }
    
  
    
    
    
}
?>
